package com.custom.web.base;

import com.custom.action.model.ActiveBaseModel;
import com.custom.action.core.annotations.DbField;
import com.custom.action.core.annotations.DbJoinField;
import com.custom.action.core.annotations.DbJoinTable;
import com.custom.action.core.annotations.DbJoinTables;
import com.custom.comm.date.DateTimeUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * @author XiaoBai
 * @since 2024/3/2 0002 15:06
 */
@Getter
@Setter
@DbJoinTables({
        @DbJoinTable("left join user_info cus on cus.id = a.create_user_id"),
        @DbJoinTable("left join user_info uus on uus.id = a.update_user_id")
})
public class BaseTableInfo<T> extends ActiveBaseModel<T, Integer> {

    /**
     * 创建时间
     */
    @DbField(value = "create_time")
    @ApiModelProperty(value = "创建时间")
    private Integer createTime;

    /**
     * 创建人ID
     */
    @DbField(value = "create_user_id")
    @ApiModelProperty(value = "创建人ID")
    private Integer createUserId;

    @DbJoinField("cus.name")
    @ApiModelProperty(value = "创建人名称")
    private String createUserName;

    /**
     * 最后修改时间
     */
    @DbField(value = "update_time")
    @ApiModelProperty(value = "最后修改时间")
    private Integer updateTime;

    /**
     * 最后修改人ID
     */
    @DbField(value = "update_user_id")
    @ApiModelProperty(value = "最后修改人ID")
    private Integer updateUserId;

    @DbJoinField("uus.name")
    @ApiModelProperty(value = "最后修改人名称")
    private String updateUserName;

    /**
     * 是否删除？1-是，0-否
     */
    @DbField(value = "state")
    @ApiModelProperty(value = "是否删除？1-是，0-否")
    private Integer state;


    @Override
    public void insertBefore() {
        if (createTime == null) {
            createTime = DateTimeUtils.getThisTime();
        }
        if (updateTime == null) {
            updateTime = DateTimeUtils.getThisTime();
        }
    }

    @Override
    public void updateBefore() {
        if (updateTime == null) {
            updateTime = DateTimeUtils.getThisTime();
        }
    }
}
